package com.icode.jsf.controller;

import com.icode.jsf.model.User;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

/**
 * User: alexz
 * Date: 14-10-24
 * Time: 下午6:20
 */
@ManagedBean
@ApplicationScoped
public class LoginController {

    public String login() {
        FacesContext context = FacesContext.getCurrentInstance();
        ValueBinding valueBinding = context.getApplication().createValueBinding("#{user}");
        User user = (User) valueBinding.getValue(context);
        if (user.isValid()) {
            return "index";
        }
        return "welcome";
    }
}
